package com.yiying.xianjindai.activity;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.yinglan.alphatabs.AlphaTabsIndicator;
import com.yiying.xianjindai.R;
import com.yiying.xianjindai.fragment.BillFragment;
import com.yiying.xianjindai.fragment.HomeFragment;
import com.yiying.xianjindai.fragment.MyFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private List<Fragment> mFragments;
    private ViewPager viewPager;
    private MyAdapter adapter;
    private AlphaTabsIndicator mAlphaIndicator;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewPager = findViewById(R.id.viewPager);
        mAlphaIndicator = findViewById(R.id.AlphaTabsIndicator);
        initData();

    }

    private void initData() {
        BillFragment  billFragment = new BillFragment();
        HomeFragment homeFragment = new HomeFragment();
        MyFragment  myFragment = new MyFragment();
        mFragments = new ArrayList<>();
        mFragments.add(billFragment);
        mFragments.add(homeFragment);
        mFragments.add(myFragment);
        //ViewPager的适配器
        adapter = new MyAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        mAlphaIndicator.setViewPager(viewPager);
    }
    class MyAdapter extends FragmentPagerAdapter {

        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }
    }

}
